package com.sbr.seb.planning.dao.jpa.impl;

import java.util.List;

import javax.persistence.Query;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sbr.genericdao.jpa.JPADAO;
import com.sbr.seb.entity.livraison.Application;
import com.sbr.seb.entity.livraison.Version;
import com.sbr.seb.planning.dao.ApplicationDao;

public class ApplicationDaoJpaImpl extends JPADAO<Application> implements ApplicationDao {

	protected static final Logger logger = LoggerFactory.getLogger(ApplicationDaoJpaImpl.class);
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Version> findAllVersions(Application application) {
		Query query = entityManager.createQuery("SELECT v FROM Version v, Application a WHERE a.id=:application AND a.id=v.application.id");
		query.setParameter("application", application.getId());
		List<Version> versionList = query.getResultList();
		logger.info("{}",versionList);
		return  versionList;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Version> findAllVersions() {
		Query query = entityManager.createQuery("SELECT v FROM Version v, Application a WHERE a.id=v.application.id ORDER BY Application ASC");
		return query.getResultList();
	}

}
